<?php
class MainPage extends Smarty {

    var $pageTitle = 'Vinod-Vsworx FrameWork Home';
    var $metaKeywords = '';
    var $metaDescription = '';
    var $header = '';
    var $leftPanel = '';
    var $midPart = '';
    var $footer = '';

    var $cssStyleFiles = array("global.css"); //Default Css
    var $jsFiles = array(); //Default JS

    public function __construct() {
        
		global $request;
        $this->debugging = false;
        
        $this->template_dir = VIEW_PATH."Default/tpl/";
        $this->compile_dir = VIEW_PATH."Default/tpl_c/";

        if(isset($_SESSION['userid']) && ($_SESSION['userid'])) {

            $this->assign("logout_url", $request->createURL("User", "doLogout"));
            $this->assign("home_url", $request->createURL("", ""));
            $this->assign("edit_profile_url", $request->createURL("User","edit"));
            $this->assign("change_pass_url", $request->createURL("User", "password"));
            $this->assign("blogs_url", $request->createURL("User", "loadall"));
        }
    }

    function addJsFile($file) {
        $this->jsFiles[] = $file;
    }

    function loadJsFiles() {
        foreach ($this->jsFiles as $jsFile) {
            echo "<script src=\"".JS_PATH."$jsFile\" type=\"text/javascript\" language=\"javascript\"></script>";
        }
    }

    function addCssStyle($file) {
        $this->cssStyleFiles[] = $file;
    }

    function loadCssStyle() {
        foreach ($this->cssStyleFiles as $cssFile) {
            echo "<link href=\"".CSS_PATH."$cssFile\" rel=\"stylesheet\" type=\"text/css\" />";
        }
    }

    function getPage($midPage) {
        
        global $request;
        
        $this->assign("IMAGES_PATH", IMAGES_PATH);
        $this->assign("page_title", $this->pageTitle);
        $this->assign("css_files", $this->loadCssStyle());
        $this->assign("js_files", $this->loadJsFiles());
        $this->assign("meta_description", $this->metaDescription);
        $this->assign("meta_keywords", $this->metaKeywords);
        
        $this->display("header.tpl");
        if($request->getAttribute("message")) {
            $this->assign("alert_msg", $this->renderMsg($request->getAttribute("message")));
            $this->display("alert.tpl");
        }
        $this->display($midPage);
        $this->display("footer.tpl");
    }

    private function renderMsg($msg) {
        
        return (is_array($msg))?implode("<br />", $msg):$msg;
    }
}
?>